<!DOCTYPE HTML>
<html>
<head>
  <meta charset="utf-8">
  <title>键盘控制移动</title>
   <style> 
    #div1{width:100px;height:100px;background:#CCC;position:absolute;}
   </style>
   <script>
      document.onkeydown=function(ev){
	    var oEvent=ev||event;
	    var oDiv=document.getElementById("div1");
		if(oEvent.keyCode==37){
		   oDiv.style.left=oDiv.offsetLeft-10+'px';
		
		}else if(oEvent.keyCode==39){oDiv.style.left=oDiv.offsetLeft+10+'px';} 
	  }
   </script>
</head>
<body>
  <div id="div1"></div>


</body>
</html>